package com.wangc.report.controller;

import com.wangc.report.entity.TaskLogEntity;
import com.wangc.report.service.TaskLogService;
import com.wangc.report.utils.PageUtils;
import com.wangc.report.utils.Query;
import com.wangc.report.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Controller
 *
 * @author wangc
 * @email 1620415297@qq.com
 * @date 2020-10-20 14:13:58
 */
@RestController
@RequestMapping("tasklog")
public class TaskLogController {
    @Autowired
    private TaskLogService taskLogService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<TaskLogEntity> taskLogList = taskLogService.queryList(query);
        int total = taskLogService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(taskLogList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        TaskLogEntity taskLog = taskLogService.queryObject(id);

        return R.ok().put("taskLog", taskLog);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TaskLogEntity taskLog) {
        taskLogService.save(taskLog);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TaskLogEntity taskLog) {
        taskLogService.update(taskLog);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        taskLogService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<TaskLogEntity> list = taskLogService.queryList(params);

        return R.ok().put("list", list);
    }
}
